package com.ys.controller.api.sys;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ys.entity.sys.YsDict;
import com.ys.service.sys.CommonApiService;
import com.ys.service.sys.YsDictService;
import com.ys.vo.LayuiTableVoJA;
import com.ys.vo.R;

@Controller
@RequestMapping("/api/inter/ysDict")
public class ApiInterYsDictController {
	
//	private static final Logger logger = Logger.getLogger(ApiAdminLoginController.class);
	
	@Autowired
	private CommonApiService<YsDict> commonApiService;
	@Autowired
	private YsDictService ysDictService;

	@RequiresPermissions("ysDict:view")
	@RequestMapping("/search")
    @ResponseBody
	public LayuiTableVoJA search(@ModelAttribute YsDict cond){
		
		cond.setOrderby("A.DictKey asc, A.SortNo asc");
		
		return commonApiService.searchLay(cond);
	}
	
	/*
	 * 删除
	 */
	@RequiresPermissions("ysDict:view")
	@PostMapping("/delete")
	@ResponseBody
	public R delete(Long id) {
		return ysDictService.deleteTrue(id);
	}
	
	/**
	 * 调整顺序
	 */
	@PostMapping("/resort")
    @ResponseBody
	public R resort(String rows){
		return ysDictService.resort(rows);
	}
	
	/**
	 * 新增字典（选择框）
	 */
	@RequiresPermissions("ysDict:view")
	@PostMapping("/add")
    @ResponseBody
	public R add(String dictKey, String dictName, String dictValue){
		return ysDictService.add(dictKey, dictName, dictValue);
	}
	
	/**
	 * 编辑字典（选择框）
	 */
	@RequiresPermissions("ysDict:view")
	@PostMapping("/edit")
    @ResponseBody
	public R edit(Long id, String dictName, String dictValue){
		return ysDictService.edit(id, dictName, dictValue);
	}
	
}
